package SortAlgorithm;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname MergeSort 归并排序
 * @Description TODO 采用分治策略 分：将问题分解成小的问题然后递归求解； 治：将分的阶段的搭配的答案修补在一起，即分而治之
 * @Date 2021/11/15 9:01
 * @Created K024851
 */
public class MergeSort {

    public static void main(String[] args) {
        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int) (Math.random() * 8000000);
        }
//        int[] arr = {8,4,5,7,1,3,6,2};
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println("排序前：" + format);
        int[] temp = new int[arr.length];
        mergeSort(arr,0, arr.length, temp);
        Date date2 = new Date();
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format2 = simpleDateFormat2.format(date2);
        System.out.println("排序后：" + format2);
    }


    public  static void mergeSort(int[] arr,int left,int right,int[] temp){
        if (left<right){
            int mid = (left+right)/2;
            mergeSort(arr,left,mid,temp);
            mergeSort(arr, mid+1, right, temp);
            merge(arr, left,mid, right, temp);
        }
    }
    public static void merge(int[] arr,int left,int mid,int right,int[] temp){
        int i = left;
        int j = mid +1;
        int t = 0;
    }

}
